import { createStore } from 'vuex'
// 引入模块
import user from './modules/user'
import cart from './modules/cart'
// 引入插件  插件默认保存到localstorage
import createPersistedstate from 'vuex-persistedstate'
import * as Cookies from 'js-cookie'

export default createStore({
  state: {
  },
  mutations: {
  },
  actions: {
  },
  modules: {
    // 合并模块
    user,
    cart
  },
  // 插件默认语法
  plugins: [
    createPersistedstate({
    //   // 存入到localstorage的key值
    //   key: 'erabbit-client-pc-store',
    //   // 存入路径
    //   paths: ['user']
      storage: {
        getItem: key => Cookies.get(key),
        setItem: (key, value) => Cookies.set(key, value, { expires: 7 }),
        removeItem: key => Cookies.remove(key)
      }
    })
  ]
})
